.DEFAULT_GOAL := exec

.PHONY: help build rebuild start stop restart up down reload ps status ls top images logs exec shell bash

# fill in service name here
APP = 'odoo_app'

# if not set, use the last service's name in `docker-compose.yml`
ifeq (${APP},'')
APP = `docker-compose config --services |tail -1`
endif

help:  ## 帮助
	@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

build:  ## 构建镜像
	docker-compose build || exit 0

rebuild: down  ## 重新构建镜像
	docker-compose build --no-cache || exit 0

start:  ## 启动容器
	docker-compose start || exit 0

stop:  ## 停止容器
	docker-compose stop --timeout 3 || exit 0

restart: stop start  ## 重启容器

up:  ## 生成容器(后台运行)
	docker-compose up -d || exit 0

down:  ## 销毁容器
	docker-compose down --timeout 3 || exit 0

reload: down up  ## 重新生成容器

ps:  ## 列出容器
	docker-compose ps || exit 0

status: ps  ## 列出容器(别名)

ls: ps  ## 列出容器(别名)

top:  ## 查看容器内进程
	docker-compose top || exit 0

images:  ## 查看容器使用的镜像
	docker-compose images || exit 0

logs:  ## 查看日志
	docker-compose logs -f --tail 100 || exit 0

exec:  ## 进入容器(默认)
	docker-compose exec ${APP} /bin/bash || exit 0

shell: exec  ## 进入容器(别名)

bash: exec  ## 进入容器(别名)
